home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.4 Applications 1997 August / SGI IRIX 6.4 Applications 1997 August.iso / dist / gateway.idb / usr / WebFace / Source / 20-NetworkServices / routing / routed-config.frm.z / routed-config.frm
Encoding:
Text File  |  1997-07-30  |  9.2 KB  |  330 lines

  1. #!/usr/bin/perl5
  2. #
  3. # routed-config.cgi
  4. #
  5. # Copyright 1988-1996 Silicon Graphics, Inc.
  6. # All rights reserved.
  7. #
  8. # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  9. # the contents of this file may not be disclosed to third parties, copied or
  10. # duplicated in any form, in whole or in part, without the prior written
  11. # permission of Silicon Graphics, Inc.
  12. #
  13. # RESTRICTED RIGHTS LEGEND:
  14. # Use, duplication or disclosure by the Government is subject to restrictions
  15. # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  16. # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  17. # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  18. # rights reserved under the Copyright Laws of the United States.
  19. #
  20. # $Id: routed-config.frm,v 1.35 1997/06/19 22:26:29 shotes Exp $
  21.  
  22. *MIMETRIC  =  0;
  23. *MAXMETRIC = 16;
  24.  
  25. BEGIN { require "/usr/WebFace/lib/CGI.pm"; import CGI; }
  26. require "/usr/OnRamp/lib/OnRamp.pm";
  27. require "/usr/OnRamp/lib/java.pm";
  28.  
  29. $query = new CGI;
  30.  
  31. $conf = "/etc/config/routed.options";
  32. $title = "Dynamic Routing";
  33.  
  34. if ($ENV{'HTTP_USER_AGENT'} =~ /Mozilla\/2/) { $br_index = 1; }
  35. else { $br_index = 0; }
  36.  
  37. $js =
  38. "br_index = $br_index;
  39. $js_standard
  40. $js_error_box
  41. $js_ip
  42. $js_filename
  43. function checkForm(form) {
  44.     if (form.enable[br_index].checked) {
  45.         if (form.logf.value != \"\")
  46.             if (!testFilename(form.logf)) return (false);
  47.         if (!testAddress(form.net)) return (false);
  48.         if (!testInt(form.metric)) return (false);
  49.     }
  50.     return (true);
  51. }
  52. function testInt(Ctrl) {
  53.     if (Ctrl.value == \"\") return (true); 
  54.     if (! checkInt(Ctrl.value, 10)) {
  55.         errorBox (Ctrl, \"The hop count must be a valid integer.\");
  56.         return (false);
  57.     }
  58.     num = parseInt(Ctrl.value); 
  59.         if (num > 16) {     
  60.         errorBox (Ctrl, \"The hop count must be less than 16.\"); 
  61.         return (false); 
  62.     } 
  63.     return (true);
  64. }
  65. function testAddress(Ctrl) {
  66.     if (Ctrl.value == \"\") return (true); 
  67.     if (!testIPaddress(Ctrl.value,false)) { 
  68.         errorBox (Ctrl, \"The network IP address \" + Ctrl.value 
  69.             + \" \\nis invalid.\"); 
  70.         return (false); 
  71.     }
  72.     return (true);
  73. }";
  74.  
  75.  
  76. print $query->header;
  77.  
  78. $enabled = &get_config("routed");
  79.  
  80. &getOptions;
  81.  
  82. if ($query->param) {
  83.     $help = $document_root . $ENV{"SCRIPT_NAME"};
  84.     $help =~ s/cgi$/hlp/;
  85.     exec $help if ($query->param('help') eq "Help");
  86.  
  87.     if ($query->param('doit') eq 'Ok') {
  88.         if ($query->param('enable') eq 'Yes') {
  89.             &formValidation;
  90.             &writeOptions;
  91.             $message = "Completed changes.";
  92.         } else { &disable; }
  93.         if (!$message) { $message = "No changes made."; }
  94.     }
  95. }
  96.  
  97. &generic;
  98.  
  99. sub error {
  100.     &error_block($_[0]);
  101.     &generic;
  102.     exit 0;
  103. }
  104.  
  105. sub writeOptions {
  106.     open (OUT,"> $conf");
  107.     $value = "";
  108.  
  109.     if ($query->param('sflag') eq "Yes") { 
  110.         $d_sflag = "Yes";
  111.         $value = "s";
  112.     } else { $d_sflag = "No"; }
  113.  
  114.     if ($query->param('gflag') eq "Yes") { 
  115.         $d_gflag = "Yes";
  116.         $value .= "g";
  117.     } else { $d_gflag = "No"; }
  118.  
  119.     if ($query->param('qflag') eq "Yes") { 
  120.         $d_qflag = "Yes";
  121.         $value .= "q";
  122.     } else { $d_qflag = "No"; }
  123.  
  124.     if ($query->param('tflag') eq "Yes") { 
  125.         $d_tflag = "Yes";
  126.         $value .= "t";
  127.     } else { $d_tflag = "No"; }
  128.  
  129.     if ($query->param('hflag') eq "Yes") { 
  130.         $d_hflag = "No";
  131.         $value .= "h";
  132.     } else { $d_hflag = "Yes"; }
  133.  
  134.     if ($query->param('mflag') eq "Yes") { 
  135.         $d_mflag = "Yes";
  136.         $value .= "m";
  137.     } else { $d_mflag = "No"; }
  138.     
  139.     if ($value) {print OUT "-$value\n"; }
  140.  
  141.     if ($query->param('net')) {
  142.         print OUT "-F ",$query->param('net'),",",
  143.             $query->param('metric'),"\n";
  144.         $d_net = $query->param('net');
  145.         $d_metric = $query->param('metric');
  146.     } else { $d_net = ""; $d_metric = "14"; }
  147.  
  148.     if ($query->param('logf')) {
  149.         print OUT $query->param('logf'),"\n";
  150.         $d_logfile = $query->param('logf');
  151.     } else { $d_logfile = ""; }
  152.     
  153.     close(OUT);
  154.  
  155.     system("/etc/chkconfig", "routed", "on");
  156.     system("/etc/killall", "routed");
  157.         open(IN,"< /etc/config/routed.options");
  158.         while(<IN>) {
  159.             chop($_);
  160.             $configFile .= " $_";
  161.         }
  162.         close(IN);
  163.         system("/usr/etc/routed $configFile > /dev/null 2>&1");
  164.         $enabled = "Yes";
  165. }
  166.  
  167. sub disable {
  168.     if ($enabled eq 'Yes') {
  169.     system("/etc/chkconfig", "routed", "off");
  170.     system("/etc/killall", "routed");
  171.         $enabled = "No";
  172.         $message = "Dynamic routing disabled.";
  173.     }
  174. }
  175.  
  176.  
  177. sub getOptions {
  178.     $d_sflag = "No";
  179.     $d_qflag = "No";
  180.     $d_tflag = "No";
  181.     $d_gflag = "No";
  182.     $d_hflag = "Yes";
  183.     $d_mflag = "No";
  184.     $d_Fflag = "No";
  185.     $d_logfile = $dfl_logfile = "";
  186.     $d_metric = $dfl_metric = 14;
  187.     $d_net = "";
  188.  
  189.         open(OPTIONS, $conf) || print "Cannot open $conf";
  190.         while(<OPTIONS>) {
  191.         if (/^#/) { next; }
  192.         chop;
  193.         @optlist = split(/\s+/);
  194.         $i = 0;
  195.         while ($optlist[$i]) {
  196.                 if ($optlist[$i] =~ /^\//) {
  197.             $d_logfile = $optlist[$i];
  198.             last;
  199.                 }
  200.                 @chars = split(//, $optlist[$i]);
  201.                 if ($chars[0] eq "-") {
  202.             if ($chars[1] eq "F") {
  203.                     @flt = split(/\,/, $optlist[$i+1]);
  204.                     $d_net = $flt[0];
  205.                     if ($flt[1] ne "") { $d_metric = $flt[1]; }
  206.                     $i += 2;
  207.                     next;
  208.             } 
  209.             $j = 0;
  210.             while ($chars[++$j]) {
  211.                 if    ($chars[$j] eq "s") { $d_sflag = "Yes"; }
  212.                 elsif ($chars[$j] eq "q") { $d_qflag = "Yes"; }
  213.                 elsif ($chars[$j] eq "t") { $d_tflag = "Yes"; }
  214.                 elsif ($chars[$j] eq "g") { $d_gflag = "Yes"; }
  215.                 elsif ($chars[$j] eq "h") { $d_hflag = "No"; }
  216.                 elsif ($chars[$j] eq "m") { $d_mflag = "Yes"; }
  217.             }
  218.                 }
  219.                 $i++;
  220.         }
  221.     }
  222.     close(OPTIONS);
  223. }
  224.  
  225. sub formValidation {
  226.     if ($query->param('logf') && $query->param('logf') ne $d_logfile) {
  227.         my $errvar = &check_fname($query->param('logf'), 2);
  228.         &error($errvar) if $errvar; 
  229.     }
  230.  
  231.     $retNet = $query->param('net');
  232.     &error("Invalid IP address") if $retNet && &check_ipaddr($retNet);
  233.         
  234.     &error("Metric must be between $MINMETRIC and $MAXMETRIC")
  235.         if &check_int($query->param('metric'), $MINMETRIC, $MAXMETRIC);
  236. }
  237.  
  238. sub error {
  239.     &error_block($_[0]);
  240.     &generic;
  241.     exit 0;
  242. }   
  243.  
  244. sub generic {
  245.     &js_title_block($title,$js);
  246.     &header_block($title);
  247.  
  248.     open(IN,"/usr/OnRamp/bin/htnetwork | ");
  249.     $num = 0;
  250.     while(<IN>) {
  251.         @items = split(/:/);
  252.         if ($items[2] == 1) { $num++; }
  253.     }
  254.     close(IN);
  255.  
  256.     print "<i>$message</i>";
  257.  
  258.     print $query->startform("POST", "", "", "NAME=StandardForm", "onSubmit=\"return runSubmit()\"");
  259.  
  260.     print "<center><table cellpadding=5 width=450>\n";
  261.  
  262.     print "<tr><th align=left>Enable dynamic routing:\n",
  263.         "<th align=left>",
  264.               $query->radio_group(-name=>'enable',
  265.               -values=>['Yes','No'],
  266.               -default=>$enabled), "</tr>\n";
  267.  
  268.     print "<tr><th align=left>Offer default destination for unknown
  269.         routes:\n","<th align=left>",
  270.               $query->radio_group(-name=>'gflag',
  271.               -values=>['Yes','No'],
  272.               -default=>$d_gflag), "</tr>\n";
  273.  
  274.     if ($num == 1) {
  275.     print "<tr><th align=left>Force router to supply network
  276.         information:\n","<th align=left>",
  277.               $query->radio_group(-name=>'sflag',
  278.               -values=>['Yes','No'],
  279.               -default=>$d_sflag), "</tr>\n";
  280.     } else {
  281.     print "<tr><th align=left>Force router to suppress network
  282.         information:\n","<th align=left>",
  283.               $query->radio_group(-name=>'qflag',
  284.               -values=>['Yes','No'],
  285.               -default=>$d_qflag), "</tr>\n";
  286.     }
  287.  
  288.     print "<tr><th align=left>Print all inbound and outbound 
  289.         packets to standard output device:\n","<th align=left>",
  290.               $query->radio_group(-name=>'tflag',
  291.               -values=>['Yes','No'],
  292.               -default=>$d_tflag), "</tr>\n";
  293.  
  294.     print "<tr><th align=left>Advertise host routes 
  295.         on the primary interface:\n","<th align=left>",
  296.               $query->radio_group(-name=>'mflag',
  297.               -values=>['Yes','No'],
  298.               -default=>$d_mflag), "</tr>\n";
  299.  
  300.     print "<tr><th align=left>Advertise host 
  301.         routes on secondary interfaces:\n","<th align=left>",
  302.               $query->radio_group(-name=>'hflag',
  303.               -values=>['Yes','No'],
  304.               -default=>$d_hflag), "</tr>\n";
  305.  
  306.     print "</table><table width=450 cellpadding=5>\n";
  307.  
  308.     print "<tr><th align=left>Filename for logging routing events:
  309.             </th><th align=right>",
  310.               $query->textfield(-name=>'logf',
  311.             -default=>$d_logfile,
  312.             -size=>20, -maxlength=>256), "</th></tr>\n";
  313.  
  314.     print "</table><table width=450 cellpadding=5>\n";
  315.  
  316.     print "<tr><th align=left>Filter out routes to network ",
  317.         $query->textfield(-name=>'net', -default=>$d_net, -size=>15),
  318.         "\n and replace with a default route with hop count of: ",
  319.         $query->textfield(-name=>metric, -size=>3, -default=>$d_metric),
  320.         "</tr>\n";
  321.  
  322.     print "</table></font></center>";
  323.  
  324.      print "<br>\n";
  325.  
  326.     print &js_buttons('doit','Ok','onClick="markOK()"','onClick="markOther()"');
  327.  
  328.     print $query->endform;
  329. }
  330.